<template>
  <div class="mod-config">
    <table-view ref="view"
                :searchAttrs="searchAttrs"
                :primaryKey="primaryKey"
                :listApiName="listApiName"
                :deleteApiName="deleteApiName"
                :saveAuthName="saveAuthName"
                :deleteAuthName="deleteAuthName"
                :showAttrs="showAttrs"
                :optionWidth="200"
    >
      <template v-slot:foot="{scope}">
        <el-tooltip class="item" effect="dark" content="导出采购合同" placement="bottom" :hide-after="1800" :open-delay="800">
          <el-button type="text" size="small" @click="exportPurchaseContract(R.path(['row', primaryKey], scope))">
            合同
          </el-button>
        </el-tooltip>
      </template>
    </table-view>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <purchase-model-add-or-update v-if="purchaseModelVisible" ref="purchaseModel"></purchase-model-add-or-update>
    <purchase-part-add-or-update v-if="purchasePartVisible" ref="purchasePart"></purchase-part-add-or-update>
    <model-info-add-or-update v-if="modelInfoVisible" ref="modelInfo"></model-info-add-or-update>

  </div>
</template>


<script>
import tableView from '@/components/tableView'
import basicMixins from '@/utils/commonViewMixins'
import AddOrUpdate from './contractpurchaseinfo-add-or-update'
import {exportHandle} from '@/utils'

import purchaseModelAddOrUpdate from '../purchase/purchasemodel-add-or-update'
import purchasePartAddOrUpdate from '../purchase/purchasepart-add-or-update'
import ModelInfoAddOrUpdate from '@/views/modules/model/modelinfo-add-or-update'

export default {
  mixins: [basicMixins],
  data() {
    return {
      purchaseModelVisible: false,
      purchasePartVisible: false,
      modelInfoVisible: false,
      primaryKey: 'id',
      listApiName: 'contractApi/listContractPurchaseInfoList',
      deleteApiName: 'contractApi/deleteContractPurchaseInfo',
      saveAuthName: 'contract:contractpurchaseinfo:save',
      deleteAuthName: 'contract:contractpurchaseinfo:delete',
      searchAttrs: {
        commodityNoList: {
          label: '商品编号',
          placeholder: '请输入商品编号'
        },
        purchaseContractNo: {
          label: '合同编号',
          placeholder: '请输入合同编号'
        },
        supplierId: {
          label: '供应商名称',
          clearable: true,
          type: 'autoComplete',
          placeholder: '请输入供应商名称',
          querySearchApiName: 'supplierApi/getSupplierList'
        },
        dateTimeRange: {
          type: 'date',
          dateType: 'daterange',
          clearable: true
        },

      },
      showAttrs: {
        purchaseContractNo: {
          label: '采购合同编号',
          // showAuthName: 'contractNo'
          width: 140,
        },
        purchaseType: {
          label: '采购类型',
          type: 'radio',
          width: 110,
          items: [
            {value: 1, text: '光瓶',tagType:'success'},
            {value: 23, text: '纸箱',tagType: 'danger'},
            {value: 25, text: '礼盒',tagType: 'danger'},
            {value: 3, text: '喷头',tagType: 'success'},
            {value: 4, text: '中套'},
            {value: 5, text: '披肩',tagType: 'warning'},
            {value: 6, text: '塑料盖',tagType:'warning'},
            {value: 7, text: '锌合金盖',tagType:'danger'},
            {value: 8, text: '香薰棒',tagType:'danger'},
            {value: 9, text: '树脂盖',tagType:'success'},
            {value: 11, text: '深加工',tagType:'danger'},
            {value: 66, text: '滚珠',tagType:'info'},
            {value: 77, text: '电化铝盖',tagType:'warning'},
            {value: 88, text: '软管类',tagType:'info'},
            {value: 99, text: '其它',tagType:'danger'},
            {value: 100, text: '配件'},
            {value: 111, text: '拉管玻璃瓶'},
            {value: 999, text: '标牌',tagType:'info'},
            {value: 666, text: '木头竹子盖'},
            {value: 888, text: '膏霜罐'},
            {value: 8888, text: '小喷雾乳液泵',tagType:'success'},
            {value: 88888, text: '香水樽',tagType:'warning'},
            {value: 888888, text: '塑料瓶'},
          ]
        },
        supplierName: {
          label: '供应商',
          width: 140
        },
        commodityNoList: {
          label: '采购商品'
        },
        contractTime: {
          label: '采购合同日期',
          type: 'date', width: 110
        },
        deliveryTime: {
          label: '交货日期',
          type: 'date', width: 95
        },
        paymentCycle:{
          label: '付款周期',
          type: 'radio',
          radioBorder: false,
          items: [
            {value: 0, text: '月结',tagType:'success'},
            {value: 1, text: '款到发货'},
            {value: 2, text: '3个月账期',tagType: 'info'},
            {value: 3, text: '付30%定金，余款70%款到发货',tagType: 'warning'},
            {value: 4, text: '2个月账期',tagType: 'danger'},
          ],
          default: 0
        },
        status: {
          label: '状态',
          type: 'radio',
          width: 110,
          items: [
            {value: 0, text: '草稿',tagType:'info'},
            {value: 2, text: '采购中'},
            {value: 8, text: '采购完成',tagType:'success'}

          ]
        },
        totalAmount: {
          label: '总金额',
          width: 140,
          type: 'money',
        },
        paymentAmount:{
          label: '已付金额',
          width: 140,
          type: 'money'
        },
        differenceValue:{
          label: '差额',
          type: 'numberComparison',
          warningNumberAttr: 'totalAmount',
          residueWeightCount: 'paymentAmount'
        },
      }
    }
  },
  components: {
    tableView,
    AddOrUpdate,
    purchaseModelAddOrUpdate,
    ModelInfoAddOrUpdate,
    purchasePartAddOrUpdate
  },
  methods: {
    openModelInfoDialog(cb) {
      this.modelInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.modelInfo)) {
          this.$refs.modelInfo.init(null, {status: 1}, cb)
        }
      })
    },
    openPurchaseModelDialog(cb) {
      this.purchaseModelVisible = true

      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.purchaseModel)) {
          this.$refs.purchaseModel.init(null, {}, cb, false)
        }
      })
    },
    openPurchasePartDialog(cb) {
      this.purchasePartVisible = true

      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.purchasePart)) {
          this.$refs.purchasePart.init(null, {}, cb, false)
        }
      })
    },
    openOrderDialog(param, cb) {
      this.purchasePartVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.purchasePart)) {
          this.$refs.purchasePart.init(param.id, param, cb, false)
        }
      })
    },
    exportPurchaseContract(id) {
      exportHandle('contractApi/getPurchasePartContractExport', {contractPurchaseId: id})
    }
  }
}
</script>
